package com.ruoyi.web.controller.order.mapper;

import com.ruoyi.common.core.dao.BaseMapper;
import com.ruoyi.common.entity.BO.MemberConsumeBO;
import com.ruoyi.common.entity.DO.order.ShopPetrolOrderDO;
import com.ruoyi.common.entity.VO.member.MemberSearchVO;
import com.ruoyi.common.entity.VO.order.ShopOrderSearchVO;
import com.ruoyi.common.entity.VO.order.ShopPetrolOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

public interface IBackShopPetrolOrderMapper extends BaseMapper<ShopPetrolOrderDO> {

    List<ShopPetrolOrderVO> searchList(ShopOrderSearchVO searchVO);

    List<MemberConsumeBO> searchMemberList(MemberSearchVO searchVO);

    @Select("SELECT id,coupon_id couponId,member_id memberId FROM shop_petrol_order WHERE order_status=0 and pay_status=0 and DATE_FORMAT(create_time, '%Y-%m-%d %H:%M')<=#{yesterday}")
    List<ShopPetrolOrderDO> selectPayExpiredOrderList(String yesterday);

    @Update("UPDATE shop_petrol_order set pay_status = #{payStatus} WHERE order_sn = #{orderSn}")
    int updatePayStatusByOrderSn(@Param("orderSn") String orderSn, @Param("payStatus") Integer payStatus);

    @Update("SELECT COUNT(1) FROM  shop_petrol_order WHERE order_sn = #{orderSn} and order_status=10 and pay_status=2")
    int checkIsValidRefund(String orderSn);

    @Select("SELECT SUM(pay_cost) FROM shop_petrol_order WHERE shop_id=#{shopId} and pay_way=0 and order_status=3 and pay_status=1")
    BigDecimal sumBalancePayTotal(Long shopId);
}
